import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;


public class ScenarioPanel extends JPanel 
{
	static DMserver server;
	public ScenarioPanel(final DMserver server)
	{
		GridLayout layout = new GridLayout(4,2);
		
		JButton btnWizzardattk = new JButton("wizzard attack ");
		JButton btnGoblin1attk = new JButton("goblin 1 attack");
		JButton btnGoblin2attk = new JButton("goblin 2 attack");
	
		
		setLayout(layout);
		add(btnWizzardattk);
		add(btnGoblin1attk);
		add(btnGoblin2attk);
		
		btnWizzardattk.addActionListener(new ActionListener()
		{

			@Override
			public void actionPerformed(ActionEvent arg0) 
			{
				try 
				{
					new WizzardAttack(server);
				}
				catch (Exception e) {e.printStackTrace();}
			}	
		});
		
		btnGoblin1attk.addActionListener(new ActionListener()
		{

			@Override
			public void actionPerformed(ActionEvent arg0) 
			{
				try 
				{
					int toHit = GameEngine.roll(100) + 12;
					int damage = GameEngine.roll(2,7,2);
					if (!server.getInput().equals(""))
					{
					int target = Integer.parseInt(server.getInput());
					server.sendAttack(toHit, damage,target);
					}
					else
					{
						System.out.println("attack:" + toHit + " damage:" + damage);
						server.writeMessage("attack:" + toHit + " damage:" + damage);
					}
				}
				catch (Exception e) {e.printStackTrace();}
			}	
		});
		
		btnGoblin2attk.addActionListener(new ActionListener()
		{

			@Override
			public void actionPerformed(ActionEvent arg0) 
			{
				try 
				{
					int toHit = GameEngine.roll(100) + 1;
					int damage = GameEngine.roll(1,21);
					if (!server.getInput().equals(""))
					{
					int target = Integer.parseInt(server.getInput());
					server.sendAttack(toHit, damage,target);
					}
					else
					{
						System.out.println("attack:" + toHit + " damage:" + damage);
						server.writeMessage("attack:" + toHit + " damage:" + damage);
					}
				}
				catch (Exception e) {e.printStackTrace();}
			}	
		});
	}
	
}
